from Accounting.Entity.Base import Fund
from Accounting.Entity.Feeder import *
from DataAccess.DBConnFactory import DBConnFactory


class Master(Fund):
	def __init__(self, id):
		Fund.__init__(self, id, None)
		
		
	def create_children(self):
		ids = self.query_children_id()
		#print 'debug, master_id=', self.id, 'children id=', ids
		self.children_roster = {}
		
		for item in ids:
			tmp = Feeder(item, self)
			tmp.create_children()
			
			self.children_roster[item] = tmp
			
			
	def find_child(self, id):	
		r = Fund.find_child(self, id)
		if r:
			return r
				
		for item in self.children_roster.values():
			tmp = item.find_child(id)
			if tmp:
				return tmp
					
		return None
			